﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using ACFaceAPI.yufan.Result;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RestSharp;

namespace ACFaceAPI.yufan
{
    /// <summary>
    /// 宇泛人脸客户端
    /// </summary>
    /// <remarks>
    /// 杭州宇泛智能科技有限公司人脸API-设备端
    /// 离线版本_接口文档_V4.0.8
    /// </remarks>
    public class YuFanClient
    {
        /// <summary>
        /// 密码
        /// </summary>
        public string FacePass { get; set; } = "12345678";
        /// <summary>
        /// URL
        /// </summary>
        public string FaceIPPort { get; set; } = "http://192.168.10.87:5000";
        /// <summary>
        /// 获取RestClient客户端
        /// </summary>
        public RestClient RClient { get; private set; }
        /// <summary>
        /// 获取或设置请求类
        /// </summary>
        private RestRequest RRequest { get; set; }

        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="httpAndPort">地址和端口</param>
        /// <param name="passwd">密码(可先不设置)</param>
        public YuFanClient(string httpAndPort,string passwd="")
        {
            FaceIPPort = httpAndPort;
            FacePass = passwd;
            RClient = new RestClient(FaceIPPort);
            RRequest = new RestRequest();
            //RRequest.AddHeader("Content-Type", "application/x-www-form-urlencoded");
        }

        /* 所有接口返回的数据，都包含至少四个字段
        /// result      表示处理结果（1成功，0失败）、
        /// success     操作结果（true成功，false失败）、
        /// msg         返回信息、
        /// code        返回码。
        /// result、success和msg称为基本字段。
        */
        #region 一、设备管理类接口

        /// <summary>
        /// 1.1设置设备密码
        /// </summary>
        /// <param name="oldPass">旧密码</param>
        /// <param name="newPass">新密码</param>
        public YuFanResult SetPassword(string oldPass,string newPass)
        {
            RRequest.Resource = "setPassword";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("oldPass", oldPass, ParameterType.GetOrPost);
            RRequest.AddParameter("newPass", newPass, ParameterType.GetOrPost);
            var r = RClient.Execute(RRequest, Method.GET);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.2设备序列号获取
        /// </summary>
        public YuFanResult GetDeviceKey()
        {
            RRequest.Resource = "getDeviceKey";
            RRequest.Parameters.Clear();
            var r = RClient.Execute(RRequest, Method.GET);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.3设置设备配置
        /// </summary>
        /// <param name="config">Json配置</param>
        /// <returns></returns>
        public YuFanResult SetDeviceConfig(JObject config)
        {
            RRequest.Resource = "setConfig";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("pass", FacePass);
            RRequest.AddParameter("config", config);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.4获取设备配置
        /// </summary>
        /// <returns></returns>
        public YuFanResultConfig GetDeviceConfig()
        {
            RRequest.Resource = "device/config";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("pass", FacePass);
            var r = RClient.Execute(RRequest, Method.GET);
            return JsonConvert.DeserializeObject<YuFanResultConfig>(r.Content);
        }

        /// <summary>
        /// 1.5识别模式配置
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public YuFanResult SetIdentifyModel(JObject config)
        {
            RRequest.Resource = "device/setIdentifyModel";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("pass", FacePass);
            RRequest.AddParameter("config", config);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.6设置陌生人串口韦根输出
        /// </summary>
        /// <param name="relaySwitch">继电器开关量 0:关,1:开(默认)</param>
        /// <param name="serialOutMode">串口输出类型 0:关闭,1:开门(默认),2:自定义</param>
        /// <param name="serialOutContent">串口自定义内容;只允许数字、英文和英文字符，长度限制255 个字符</param>
        /// <param name="weigenContent">韦根自定义内容;</param>
        /// <returns></returns>
        public YuFanResult SetStrangerOutInfo(int relaySwitch,int serialOutMode,string serialOutContent,string weigenContent)
        {
            RRequest.Resource = "setStrangerOutInfo";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("pass", FacePass);
            RRequest.AddParameter("relaySwitch", relaySwitch);
            RRequest.AddParameter("serialOutMode", serialOutMode);
            RRequest.AddParameter("serialOutContent", serialOutContent);
            RRequest.AddParameter("weigenContent", weigenContent);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.7隐藏IP、设备序列号、人数
        /// </summary>
        /// <param name="showIp">设备IP 0:显示(默认) 1:隐藏</param>
        /// <param name="showDeviceKey">设备序列号 0:显示(默认) 1:隐藏</param>
        /// <param name="showPeopleNum">人员/照片 0:显示(默认) 1:隐藏</param>
        /// <returns></returns>
        public YuFanResult HideConfig(int showIp=0,int showDeviceKey=0,int showPeopleNum=0)
        {
            RRequest.Resource = "";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("pass", FacePass);
            RRequest.AddParameter("showIp", showIp);
            RRequest.AddParameter("showDeviceKey", showDeviceKey);
            RRequest.AddParameter("showPeopleNum", showPeopleNum);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.8修改logo
        /// </summary>
        /// <param name="imgBase64">logo 图片的Base64 编码字符串</param>
        /// <remarks>
        /// 不加头部，如：data:image/jpg;base64
        /// 传入-1 就表示把之前设置的img2 清除掉，并显示默认图片
        /// 图片尺寸暂无强行限定条件，最终会压缩显示为长宽1:1 的图片尺寸。尺寸建议不要过大。
        /// 图片格式支持JPG、PNG 和JPEG
        /// </remarks>
        public YuFanResult ChangeLogo(string imgBase64)
        {
            RRequest.Resource = "changeLogo";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("pass", FacePass);
            RRequest.AddParameter("imgBase64", imgBase64);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.9修改img1
        /// </summary>
        /// <param name="imgBase64">img1 图片的Base64 编码字符串</param>
        /// <remarks>
        /// 不加头部，如：data:image/jpg;base64
        /// 传入-1 就表示把之前设置的img2 清除掉，并显示默认图片
        /// 图片尺寸暂无强行限定条件，最终会压缩显示为长宽1:1 的图片尺寸。尺寸建议不要过大。
        /// 图片格式支持JPG、PNG 和JPEG
        /// </remarks>
        public YuFanResult ChangeImg(string imgBase64)
        {
            RRequest.Resource = "device/img1";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("base64", imgBase64, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.10 设置屏幕方向
        /// </summary>
        /// <param name="orientation">默认横屏，1：横屏，2：竖屏</param>
        /// <remarks>
        /// 该接口成功调用后，约3 秒钟之后手动断电重启设备或调用设备重启接口，屏幕方向设置在设备重启后生效
        /// 修改屏幕方向只对一代设备生效
        /// </remarks>
        public YuFanResult SetScreenOrt(string orientation)
        {
            RRequest.Resource = "setScreenOrt";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("pass", FacePass,ParameterType.RequestBody);
            RRequest.AddParameter("orientation", orientation, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.11设置有线网络
        /// </summary>
        /// <param name="isDHCPMod">是否DHCP 1自动,2手动</param>
        /// <param name="ip">IP地址</param>
        /// <param name="gateway">网关</param>
        /// <param name="subnetMask">子网掩码</param>
        /// <param name="DNS">DNS</param>
        /// <remarks>
        /// 设备配置为DHCP 模式，自动获取动态IP，无须传入其余参数
        /// 手动设置静态IP，除subnetMask 外其余参数必须传入且不可为空
        /// 设备网络通畅，则每分钟都会自动刷新IP 地址
        /// </remarks>
        public YuFanResult SetNetInfo(int isDHCPMod,string ip="",string gateway="",string subnetMask="",string DNS="")
        {
            RRequest.Resource = "setNetInfo";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("isDHCPMod", isDHCPMod, ParameterType.RequestBody);
            if (isDHCPMod == 2)
            {
                RRequest.AddParameter("ip", ip, ParameterType.RequestBody);
                RRequest.AddParameter("gateway", gateway, ParameterType.RequestBody);
                RRequest.AddParameter("subnetMask", subnetMask, ParameterType.RequestBody);
                RRequest.AddParameter("DNS", DNS, ParameterType.RequestBody);
            }
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.12设置无线网络
        /// </summary>
        /// <param name="config">Wifi的Json配置</param>
        /// <remarks>
        /// 自动获取IP:{"ssId":"TP-LINK_E2.4G","pwd":"test-1234","isDHCPMod":true}
        /// 固定IP:{"ssId":"TP-LINK_E2.4G","pwd":"test-1234","isDHCPMod":false,"ip":"192.168.20.66","gateway":"192.168.20.1","dns":"8.8.8.8","subnetMask":"255.255.255.0"}
        /// </remarks>
        public YuFanResult SetWifiInfo(JObject config)
        {
            RRequest.Resource = "setWifi";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("wifiMsg", config, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.13设置设备时间
        /// </summary>
        /// <param name="timestamp">Unix 毫秒级时间戳</param>
        /// <remarks>
        /// 若设备连入公网，设备本身有网络时间校对机制，每隔1 分钟会联网校对一次时间，将设备时间调整与公网时间一致
        /// </remarks>
        public YuFanResult SetTime(string timestamp)
        {
            RRequest.Resource = "setTime";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("timestamp", timestamp, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.14设置屏保待机时间
        /// </summary>
        /// <param name="time">默认3 分钟。1-60分钟</param>
        /// <returns></returns>
        public YuFanResult ScreenSaverTime(int time)
        {
            RRequest.Resource = "screenSaverTime";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("time", time, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.15重启设备
        /// </summary>
        public YuFanResult DeviceReboot()
        {
            RRequest.Resource = "restartDevice";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.16重置设备
        /// </summary>
        /// <param name="delete">选择性删除 True:所有信息 Falst:不包含设备配置</param>
        /// <returns></returns>
        public YuFanResult DeviceReset(bool delete)
        {
            RRequest.Resource = "device/reset";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("delete", delete, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.17设备禁用/启用
        /// </summary>
        /// <param name="isDisable">true：禁用，false：解除禁用</param>
        /// <remarks>
        /// 禁用界面图片可通过修改禁用图片接口修改
        /// </remarks>
        public YuFanResult DeviceSetState(bool isDisable)
        {
            RRequest.Resource = "device/disable";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("isDisable", isDisable, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.18设备升级
        /// </summary>
        /// <param name="url">下载OTA 升级包地址</param>
        /// <remarks>
        /// 设备开始下载，但文件不一定正确，是否安装成功需要查看设备具体界面
        /// </remarks>
        public YuFanResult DeviceUpgrade(string url)
        {
            RRequest.Resource = "device/upgrade";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("url", url, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.19设置识别回调
        /// </summary>
        /// <param name="callbackUrl">回调地址</param>
        /// <param name="base64Enable">现场照base64开关  1：关（默认） 2：开</param>
        /// <remarks>
        /// 设备成功识别人员后，会向该地址POST 字段deviceKey、time、ip、personId、path、idcardNum、mode、passTimeType、permissionTimeType、aliveType、identifyType、data、type：face/card_0/1/2，参见回调字段说明
        /// 传入内容为空可以清空回调地址，清空后识别成功将不再进行回调
        /// </remarks>
        public YuFanResult SetCallBackIdentify(string callbackUrl="",int base64Enable=1)
        {
            RRequest.Resource = "setIdentifyCallBack";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("callbackUrl", callbackUrl, ParameterType.RequestBody);
            RRequest.AddParameter("base64Enable", base64Enable, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.20设置注册照片回调
        /// </summary>
        /// <param name="url">回调地址</param>
        /// <param name="base64Enable">现场照base64开关  1：关（默认） 2：开</param>
        /// <remarks>
        /// 照片注册成功（包括设备拍照注册）后，设备会向预先设置的回调接口POST 字段deviceKey、personId、time、newImgPath、imgPath、ip、feature、featureKey，参见回调字段说明
        /// 传入内容为空可以清空回调地址，清空后照片注册成功将不再进行回调
        /// </remarks>
        public YuFanResult SetCallBackImgReg(string url,int base64Enable)
        {
            RRequest.Resource = "setImgRegCallBack";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("url", url, ParameterType.RequestBody);
            RRequest.AddParameter("base64Enable", base64Enable, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.21设置心跳回调
        /// </summary>
        /// <param name="url">回调地址</param>
        /// <remarks>
        /// 设备每隔一分钟会向该接口POST 字段deviceKey、time、ip、personCount、faceCount、version、freeDiskSpace、cpuUsageRate、cpuTemperature 和memoryUsageRate，参见回调字段说明
        /// 传入内容为空可以清空回调地址，清空后设备心跳将不再进行回调
        /// </remarks>
        public YuFanResult SetCallBackDeviceHeartBeat(string url)
        {
            RRequest.Resource = "setDeviceHeartBeat";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("url", url, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.22设置事件回调
        /// </summary>
        /// <param name="url">回调地址</param>
        /// <remarks>
        /// 产生警报时会向该地址POST 字段参见回调字段说明
        /// 传入内容为空可以清空回调地址，清空后产生报警将不再进行回调
        /// </remarks>
        public YuFanResult SetCallBackEvent(string url)
        {
            RRequest.Resource = "device/eventCallBack";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("url", url, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.23获取所有回调地址
        /// </summary>
        /// <returns></returns>
        public YuFanResult GetCallBack()
        {
            RRequest.Resource = "device/callback";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.QueryString);
            var r = RClient.Execute(RRequest, Method.GET);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.24远程开门
        /// </summary>
        /// <param name="type">1：开门2：串口3：韦根4：表示自定义文字弹框、自定义语音播报；默认是1。非必传，type 不传则默认为1：开门</param>
        /// <param name="content">输出内容</param>
        /// <remarks>
        /// type=2：串口，只允许数字、英文和英文字符，长度限制255 个字符。
        /// type=3：韦根，只允许数字。
        /// type=4：自定义弹窗、语音播报content={"ttsModContent":"自定义语音","displayModContent":"自定义文字"}
        /// </remarks>
        public YuFanResult OpenDoor(int type,string content)
        {
            RRequest.Resource = "device/openDoorControl";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("type", type, ParameterType.RequestBody);
            RRequest.AddParameter("content", content, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.25设备系统模式切换
        /// </summary>
        /// <param name="systemMode">1:在线模式WO,2:离线模式LAN,设备处于WO模式且绑定情况下,无法调用此接口</param>
        /// <remarks>
        /// 注意：系统切换后，设备内存储所有人员、照片数据都会清空，只保留设备密码(pass)、有线/无线网络配置和设备日志
        /// 若未设置过设备密码，则调用此接口不需要pass
        /// </remarks>
        public YuFanResult SystemMode(string systemMode)
        {
            RRequest.Resource = "device/systemMode";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("systemMode", systemMode, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.26设备系统模式切换图标(是否只允许通过接口进行模式切换)
        /// </summary>
        /// <param name="isShow">是否显示系统切换图标.true：显示 false：隐藏</param>
        public YuFanResult SystemModeIcon(string isShow)
        {
            RRequest.Resource = "device/systemModeIcon";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("isShow", isShow, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.27数据读出
        /// </summary>
        /// <returns></returns>
        public YuFanResult ReadSecretKey()
        {
            RRequest.Resource = "device/readSecretKey";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.GET);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.28数据写入
        /// </summary>
        /// <param name="writeSecretKey"></param>
        /// <returns></returns>
        public YuFanResult WriteSecretKey(string writeSecretKey)
        {
            RRequest.Resource = "device/writeSecretKey";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("writeSecretKey", writeSecretKey, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.29设置卡号注册回调
        /// </summary>
        /// <param name="url">回调地址</param>
        /// <remarks>
        /// 卡号注册成功（包括设备录入卡号注册）后，设备会向预先设置的回调接口POST 字段deviceKey、personId、time、idcardNum，参见回调字段说明
        /// 传入内容为空可以清空回调地址，清空后卡号注册成功将不再进行回调
        /// </remarks>
        public YuFanResult SetCallBackCardReg(string url)
        {
            RRequest.Resource = "setCardRegCallBack";
            RRequest.Resource = "";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("url", url, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.30获取算法版本号
        /// </summary>
        public YuFanResult GetSDKVersion()
        {
            RRequest.Resource = "getSDKVersion";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.GET);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.31设置ftp账号密码
        /// </summary>
        /// <param name="username">账号,可以为空</param>
        /// <param name="password">密码,可以为空</param>
        /// <remarks>
        /// 若未设置过ftp账号密码，默认通过ftp路径可以直接访问
        /// ftp密码设置后，如需通过URL来访问设备中存储的照片，需带上密码，否则无法访问。
        /// 涉及照片查询，识别回调，注册回调接口
        /// </remarks>
        public YuFanResult SetFtpPass(string username,string password)
        {
            RRequest.Resource = "setFTP";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("username", username, ParameterType.RequestBody);
            RRequest.AddParameter("password", password, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.32语言切换
        /// </summary>
        /// <param name="languageType">语言类型</param>
        /// <remarks>
        /// “zh_CN”:中文简体;“en”:英文
        /// </remarks>
        public YuFanResult SetLanguage(string languageType)
        {
            RRequest.Resource = "device/setLanguage";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("languageType", languageType, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.33设置时区
        /// </summary>
        /// <param name="timeZone">时区</param>
        /// <remarks>
        /// “Asia/Shanghai”中国标准时间（默认）
        /// </remarks>
        public YuFanResult SetTimeZone(string timeZone)
        {
            RRequest.Resource = "device/setTimeZone";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("timeZone", timeZone, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.34获取设备信息
        /// </summary>
        /// <returns></returns>
        public YuFanResult GetInformation()
        {
            RRequest.Resource = "device/information";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.GET);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.35获取设备识别模式
        /// </summary>
        /// <returns></returns>
        public YuFanResult GetIdentifyModel()
        {
            RRequest.Resource = "device/getIdentifyModel";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.GET);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.36设置硬件接口
        /// </summary>
        /// <param name="config">设备硬件接口配置集合</param>
        /// <returns></returns>
        public YuFanResult SetHardWareInterface(JObject config)
        {
            RRequest.Resource = "device/setHardWareInterface";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("config", config, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.37获取硬件接口设置
        /// </summary>
        /// <returns></returns>
        public YuFanResult GetHardWareInterface()
        {
            RRequest.Resource = "device/getHardWareInterface";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.GET);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.38设置信号输入
        /// </summary>
        /// <param name="config">设备硬件接口配置集合</param>
        /// <returns></returns>
        public YuFanResult SetSignalInput(JObject config)
        {
            RRequest.Resource = "device/setSignalInput";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("config", config, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.39获取信号输入设置
        /// </summary>
        /// <returns></returns>
        public YuFanResult GetSignalInput()
        {
            RRequest.Resource = "device/getSignalInput";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.GET);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.40警报取消
        /// </summary>
        /// <returns></returns>
        public YuFanResult AlarmCancel()
        {
            RRequest.Resource = "device/alarmCancel";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 1.41设置测温参数
        /// </summary>
        /// <returns></returns>
        public YuFanResult SetTemperatureConfig()
        {
            throw new NotImplementedException("参数太多，准备用类传递");
            /*RRequest.Resource = "device/setTemperatureConfig";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);*/
        }

        /// <summary>
        /// 1.42设置口罩参数
        /// </summary>
        /// <param name="isMaskOpen">是否打开口罩模式 1：打开（默认）2：关闭</param>
        /// <param name="isVoiceOpen">是否口罩检测异常语音播报 1：打开（默认）2：关闭</param>
        /// <param name="voiceContext">口罩检测异常语音播报内容</param>
        /// <remarks>
        /// 打开口罩检测模式后，必须佩戴口罩才能进行识别， 关闭口罩检测模式同样可以进行口罩识别。
        /// 口罩检测异常语音播报内容，设备默认播报"请佩戴口罩"。可自定义使用其他内容，如："口罩异常警报"，voiceContext 传入空则等于默认值"请佩戴口罩"。
        /// </remarks>
        public YuFanResult SetMaskConfig(int isMaskOpen,int isVoiceOpen,string voiceContext)
        {
            RRequest.Resource = "device/setMaskConfig";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("isMaskOpen", isMaskOpen, ParameterType.RequestBody);
            RRequest.AddParameter("isVoiceOpen", isVoiceOpen, ParameterType.RequestBody);
            RRequest.AddParameter("voiceContext", voiceContext, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }
        #endregion

        #region 二、人员管理类接口
        /// <summary>
        /// 2.1人员注册
        /// </summary>
        /// <param name="person">人员信息集合</param>
        /// <returns></returns>
        public YuFanResult PersonCreate(JObject person)
        {
            RRequest.Resource = "person/create";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("person", person, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 2.2人员删除(可批量)
        /// </summary>
        /// <param name="id">人员ID；若删除多个人员，id 用英文逗号拼接，传入-1 则删除所有人员</param>
        /// <returns></returns>
        public YuFanResult PersonDelete(string id)
        {
            RRequest.Resource = "person/delete";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("id", id, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 2.3人员更新
        /// </summary>
        /// <param name="person">人员信息集合</param>
        /// <returns></returns>
        public YuFanResult PersonUpdate(JObject person)
        {
            RRequest.Resource = "person/update";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("person", person, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 2.4人员查询
        /// </summary>
        /// <param name="id">人员ID；id 传入-1 表示不局限于id 查询人员</param>
        /// <returns></returns>
        public YuFanResult PersonFind(string id)
        {
            RRequest.Resource = "person/find";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("id", id, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.GET);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 2.5人员分页查询
        /// </summary>
        /// <param name="personId">人员ID</param>
        /// <param name="length">每页最大数量</param>
        /// <param name="index">页码</param>
        /// <remarks>
        /// length 传入值要求为(0,1000]之间的正整数
        /// 若length 不传，默认值为1000，返回最近添加的1000 人
        /// 页码，从0 开始。index 的传入值必须小于总页码数，如：总页码数为1，index 只能传入0
        /// </remarks>
        public YuFanResult PersonFindByPage(string personId,int length=1000,int index=0)
        {
            RRequest.Resource = "person/findByPage";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("personId", personId, ParameterType.RequestBody);
            RRequest.AddParameter("length", length, ParameterType.RequestBody);
            RRequest.AddParameter("index", index, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 2.6人员卡号注册
        /// </summary>
        /// <param name="personId">人员ID</param>
        /// <remarks>
        /// 人员ID 必须为已存在；若不存在该人员ID，则无法进入卡号注册模式
        /// 注册成功后，可调用人员信息查询接口查询该人员的卡号
        /// </remarks>
        public YuFanResult PersonICRegist(string personId)
        {
            RRequest.Resource = "face/icCardRegist";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("personId", personId, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 2.7设置时间段通行权限
        /// </summary>
        /// <param name="passtime">某人员每日允许进入的时间段</param>
        /// <remarks>
        /// {"personId":"9eecc839cd7941c5a4d3165202dd3c32","passtime":"09:00:00,10:00:00,17:00:00,17:30:00,18:30:00,20:25:00"}
        /// 范围为[00:00:00,23:59:59]
        /// passtime 最多可设置6 段，若只设置1 段，则后几段不传即可，如：09:00:00,11:00:00
        /// </remarks>
        public YuFanResult SetPersonPasstime(string passtime)
        {
            RRequest.Resource = "person/createPasstime";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("passtime", passtime, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 2.8设置时间段通行权限(批量)
        /// </summary>
        /// <param name="personID">人员Id</param>
        /// <param name="passtime"></param>
        /// <remarks>
        /// 若设置多个人员的passtime，personId 用英文逗号拼接
        /// 传入-1 则选择为所有人员进行设置passtime
        /// {"passtime":"09:00:00,10:00:00,17:00:00,17:30:00,18:30:00,20:25:00"}
        /// 时间段格式（startTime,endTime 英文逗号隔开）
        /// passtime 最多可设置6 段，若只设置1 段，则后几段不传即可，如：09:00:00,11:00:00
        /// </remarks>
        public YuFanResult SetPersonPasstime(string personID,string passtime)
        {
            RRequest.Resource = "person/passtime";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("personID", personID, ParameterType.RequestBody);
            RRequest.AddParameter("passtime", passtime, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 2.9删除时间段权限(批量)
        /// </summary>
        /// <param name="personId">人员Id</param>
        /// <remarks>
        /// 若删除多个人员的passtime，personId 用英文逗号拼接,老离线版本仅支持传入单个personId
        /// 传入-1 可清除所有人员的passtime
        /// </remarks>
        public YuFanResult DelPersonPasstime(string personId)
        {
            RRequest.Resource = "person/deletePasstime";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("personId", personId, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 2.10设置人员有效期
        /// </summary>
        /// <param name="personId">人员ID，仅支持单个人员</param>
        /// <param name="time">有效期限时间，定时删除该人员 （年-月-日 时:分:秒）</param>
        /// <returns></returns>
        public YuFanResult SetPersonPermissions(string personId,string time)
        {
            RRequest.Resource = "person/permissionsCreate";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("personID", personId, ParameterType.RequestBody);
            RRequest.AddParameter("time", time, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 2.11设置人员有效期(批量)
        /// </summary>
        /// <param name="personId">人员Id,多个用逗号拼接</param>
        /// <param name="startTime">有效期开始时间（年-月-日 时:分:秒）</param>
        /// <param name="endTime">有效期结束时间（年-月-日 时:分:秒）</param>
        /// <returns></returns>
        public YuFanResult SetPersonPermissions(string personId,string startTime,string endTime)
        {
            RRequest.Resource = "person/permissionTime";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("personId", personId, ParameterType.RequestBody);
            RRequest.AddParameter("startTime", startTime, ParameterType.RequestBody);
            RRequest.AddParameter("endTime", endTime, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 2.12批量删除人员有效期
        /// </summary>
        /// <param name="personId">人员Id,多个用逗号拼接</param>
        /// <remarks>
        /// 传入-1，可清除所有人员的权限时间
        /// 删除该人员的权限时间设置，该人员不会被定时删除
        /// 老离线版本仅支持传入单个personId
        /// </remarks>
        public YuFanResult DelPersonPermissions(string personId)
        {
            RRequest.Resource = "person/permissionsDelete";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("personId", personId, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 2.13获取人员权限信息
        /// </summary>
        /// <param name="personId">人员Id</param>
        /// <param name="length">每页最大数量</param>
        /// <param name="index">页码</param>
        /// <returns></returns>
        public YuFanResult GetPersonPermission(string personId,int length=1000,int index=0)
        {
            RRequest.Resource = "person/permissionInfo";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("personId", personId, ParameterType.RequestBody);
            RRequest.AddParameter("length", length, ParameterType.RequestBody);
            RRequest.AddParameter("index", index, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }
        #endregion

        #region 三、照片管理类接口
        /// <summary>
        /// 3.1照片注册(base64)
        /// </summary>
        /// <param name="personId">人员ID</param>
        /// <param name="faceId">照片ID</param>
        /// <param name="imgBase64">照片的base64编码字符串</param>
        /// <param name="isEasyWay">选择宽松or严格照片注册方式</param>
        [Obsolete("不推荐使用")]
        public YuFanResult FaceCreateByBase64(string personId,string faceId,string imgBase64,bool isEasyWay=false)
        {
            RRequest.Resource = "face/create";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("personId", personId, ParameterType.RequestBody);
            RRequest.AddParameter("faceId", faceId, ParameterType.RequestBody);
            RRequest.AddParameter("imgBase64", imgBase64, ParameterType.RequestBody);
            RRequest.AddParameter("isEasyWay", isEasyWay, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 3.2照片注册(url)
        /// </summary>
        /// <param name="personId">人员ID</param>
        /// <param name="faceId">照片ID</param>
        /// <param name="imgUrl">照片url</param>
        /// <param name="isEasyWay">选择宽松or严格照片注册方式</param>
        [Obsolete("不推荐使用")]
        public YuFanResult FaceCreateByUrl(string personId, string faceId, string imgUrl, bool isEasyWay = false)
        {
            RRequest.Resource = "face/createByUrl";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("personId", personId, ParameterType.RequestBody);
            RRequest.AddParameter("faceId", faceId, ParameterType.RequestBody);
            RRequest.AddParameter("imgUrl", imgUrl, ParameterType.RequestBody);
            RRequest.AddParameter("isEasyWay", isEasyWay, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 3.3照片注册(base64+url)
        /// </summary>
        /// <param name="personId">人员ID</param>
        /// <param name="faceId">照片ID</param>
        /// <param name="url">照片url</param>
        /// <param name="base64">照片的base64 编码字符串</param>
        /// <param name="isEasyWay">选择宽松or严格照片注册方式</param>
        /// <param name="bbox">人脸框位置，用于对注册照原图提特征</param>
        /// <returns></returns>
        public YuFanResult FaceCreate(string personId,string faceId,string url="",string base64="",bool isEasyWay=false,JObject bbox=null)
        {
            RRequest.Resource = "face";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("personId", personId, ParameterType.RequestBody);
            RRequest.AddParameter("faceId", faceId, ParameterType.RequestBody);
            if (url != "")
            {
                RRequest.AddParameter("url", url, ParameterType.RequestBody);
            }
            if (base64 != "")
            {
                RRequest.AddParameter("base64", base64, ParameterType.RequestBody);
            }
            RRequest.AddParameter("isEasyWay", isEasyWay, ParameterType.RequestBody);
            if (bbox != null)
            {
                RRequest.AddParameter("bbox", bbox, ParameterType.RequestBody);
            }
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 3.4照片删除
        /// </summary>
        /// <param name="faceId">照片ID</param>
        /// <returns></returns>
        public YuFanResult FaceDelete(string faceId)
        {
            RRequest.Resource = "face/delete";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("faceId", faceId, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 3.5照片更新(base64)
        /// </summary>
        /// <param name="personId">人员ID</param>
        /// <param name="faceId">照片ID</param>
        /// <param name="imgBase64">照片的base64编码字符串</param>
        /// <param name="isEasyWay">选择宽松or严格照片注册方式</param>
        /// <returns></returns>
        public YuFanResult FaceUpdateByBase64(string personId,string faceId,string imgBase64,bool isEasyWay=false)
        {
            RRequest.Resource = "face/update";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("personId", personId, ParameterType.RequestBody);
            RRequest.AddParameter("faceId", faceId, ParameterType.RequestBody);
            RRequest.AddParameter("imgBase64", imgBase64, ParameterType.RequestBody);
            RRequest.AddParameter("isEasyWay", isEasyWay, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 3.6照片更新(base64+url)
        /// </summary>
        /// <param name="personId">人员ID</param>
        /// <param name="faceId">照片ID</param>
        /// <param name="url">照片url</param>
        /// <param name="base64">照片的base64 编码字符串</param>
        /// <param name="isEasyWay">选择宽松or严格照片注册方式</param>
        /// <param name="bbox">人脸框位置，用于对注册照原图提特征</param>
        /// <returns></returns>
        public YuFanResult FaceUpdate(string personId,string faceId,string url="",string base64="",bool isEasyWay=false,JObject bbox=null)
        {
            RRequest.Resource = "face";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("personId", personId, ParameterType.RequestBody);
            RRequest.AddParameter("faceId", faceId, ParameterType.RequestBody);
            if (url != "")
            {
                RRequest.AddParameter("url", url, ParameterType.RequestBody);
            }
            if (base64 != "")
            {
                RRequest.AddParameter("base64", base64, ParameterType.RequestBody);
            }
            RRequest.AddParameter("isEasyWay", isEasyWay, ParameterType.RequestBody);
            if (bbox != null)
            {
                RRequest.AddParameter("bbox", bbox, ParameterType.RequestBody);
            }
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 3.7照片查询
        /// </summary>
        /// <param name="personId">人员ID</param>
        /// <returns></returns>
        public YuFanResult FaceFind(string personId)
        {
            RRequest.Resource = "face/find";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("personId", personId, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 3.8拍照注册
        /// </summary>
        /// <param name="personId">人员ID</param>
        /// <returns></returns>
        public YuFanResult FaceTakeImg(string personId)
        {
            RRequest.Resource = "face/takeImg";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("personId", personId, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 3.9特征注册
        /// </summary>
        /// <param name="personId">人员ID</param>
        /// <param name="faceId">照片ID</param>
        /// <param name="feature">特征码</param>
        /// <param name="featureKey">特征秘钥</param>
        /// <param name="SDKVersion">算法版本号</param>
        /// <returns></returns>
        public YuFanResult FaceFeatureReg(string personId,string faceId,string feature,string featureKey="",string SDKVersion="")
        {
            RRequest.Resource = "face/featureReg";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("personId", personId, ParameterType.RequestBody);
            RRequest.AddParameter("faceId", faceId, ParameterType.RequestBody);
            RRequest.AddParameter("feature", feature, ParameterType.RequestBody);
            RRequest.AddParameter("featureKey", featureKey, ParameterType.RequestBody);
            RRequest.AddParameter("SDKVersion", SDKVersion, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 3.10清空人员注册照片
        /// </summary>
        /// <param name="personId">人员ID</param>
        /// <remarks>
        /// 调用该接口，该人员的所有注册照片id 会注销，并同步删除存储在设备内的该人员所有注册照片
        /// </remarks>
        public YuFanResult FaceDeletePerson(string personId)
        {
            RRequest.Resource = "face/deletePerson";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("personId", personId, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 3.11人脸照片相似性比对
        /// </summary>
        /// <param name="img1">照片1 的base64编码</param>
        /// <param name="img2">照片2 的base64编码</param>
        /// <returns></returns>
        public YuFanResult PhotoComparison(string img1,string img2)
        {
            RRequest.Resource = "photoComparison";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("img1", img1, ParameterType.RequestBody);
            RRequest.AddParameter("img2", img2, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }

        /// <summary>
        /// 3.12不兼容(强制删除)注册照查询
        /// </summary>
        /// <param name="personId">人员ID</param>
        /// <param name="length">每页最大数量</param>
        /// <param name="index">页码</param>
        /// <returns></returns>
        public YuFanResult FaceDeleteByUpdate(string personId,int length=1000,int index=0)
        {
            RRequest.Resource = "face/deleteByUpdate";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            RRequest.AddParameter("personId", personId, ParameterType.RequestBody);
            RRequest.AddParameter("length", length, ParameterType.RequestBody);
            RRequest.AddParameter("index", index, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }
        #endregion

        #region 四、识别记录
        /// <summary>
        /// 4.1识别记录查询
        /// </summary>
        /// <returns></returns>
        public YuFanResult RecordsFind()
        {
            RRequest.Resource = "newFindRecords";
            throw new NotImplementedException();
        }

        /// <summary>
        /// 4.2识别记录删除
        /// </summary>
        /// <returns></returns>
        public YuFanResult RecordsDelete()
        {
            RRequest.Resource = "newDeleteRecords";
            throw new NotImplementedException();
        }

        /// <summary>
        /// 4.3识别记录删除(通过Unix毫秒级时间戳删除)
        /// </summary>
        /// <returns></returns>
        public YuFanResult RecordsDeleteByUnixTime()
        {
            RRequest.Resource = "newDeleteRecordsByUnixTime";
            throw new NotImplementedException();
        }

        /// <summary>
        /// 4.4刷脸记录查询
        /// </summary>
        /// <returns></returns>
        public YuFanResult RecordsFaceFind()
        {
            RRequest.Resource = "findRecords";
            throw new NotImplementedException();
        }

        /// <summary>
        /// 4.5刷脸记录删除
        /// </summary>
        /// <returns></returns>
        public YuFanResult RecordsFaceDelete()
        {
            RRequest.Resource = "deleteRecords";
            throw new NotImplementedException();
        }

        /// <summary>
        /// 4.6刷脸记录删除(通过Unix毫秒级时间戳删除)
        /// </summary>
        /// <returns></returns>
        public YuFanResult RecordsFaceDeleteByUnixTime()
        {
            RRequest.Resource = "deleteRecordsByUnixTime";
            throw new NotImplementedException();
        }

        /// <summary>
        /// 4.7刷卡记录查询
        /// </summary>
        /// <returns></returns>
        public YuFanResult RecordsICFind()
        {
            RRequest.Resource = "findICRecords";
            throw new NotImplementedException();
        }

        /// <summary>
        /// 4.8刷卡记录删除
        /// </summary>
        /// <returns></returns>
        public YuFanResult RecordsICDelete()
        {
            RRequest.Resource = "deleteICRecords";
            throw new NotImplementedException();
        }

        /// <summary>
        /// 4.9刷卡记录删除(通过Unix 毫秒级时间戳删除)
        /// </summary>
        /// <returns></returns>
        public YuFanResult RecordsICDeleteByUnixTime()
        {
            RRequest.Resource = "deleteICRecordsByUnixTime";
            throw new NotImplementedException();
        }
        #endregion

        private YuFanResult YuFan()
        {
            RRequest.Resource = "";
            RRequest.Parameters.Clear();
            RRequest.AddParameter("Content-Type", "application/x-www-form-urlencoded", ParameterType.HttpHeader);
            RRequest.AddParameter("pass", FacePass, ParameterType.RequestBody);
            var r = RClient.Execute(RRequest, Method.POST);
            return JsonConvert.DeserializeObject<YuFanResult>(r.Content);
        }
    }
}
